04. CODE: The RoutePlanner Constructor

The RoutePlanner Constructor

Now that you have filled out the header of the RoutePlanner class, you can finish writing the constructor in route_planner.cpp. The constructor takes one RouteModel reference and four floats as arguments. The RouteModel reference should already be assigned to the m_Model variable. In this exercise, the floats should be used to construct the start_node and end_node of your class. Since node coordinates are scaled to values between 0 an 1, you will need to scale the floats as well in the constructor. See the instructions below for the steps on how to do this.

## To complete this exercise:

  1. Within the body of the RoutePlanner constructor:
    1. Scale the floats to percentages by multiplying each float by 0.01 and storing the result in the float variable. For example: start_x *= 0.01;
    2. Use the m_Model.FindClosestNode method to find the closest nodes to (start_x, start_y) and (end_x, end_y). Store pointers to these nodes in the start_node and end_node class variables.

Note: There are no tests for this exercise. Your code should compile, and this class will be tested in later exercises.

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: react
  • Opened files (when workspace is loaded): n/a
  • userCode:

    export CXX=g++-7
    export CXXFLAGS=-std=c++17
    cmake_tests() {
    /usr/local/bin/cmake -DTESTING="FindClosest" "$1"
    }
    export -f cmake_tests

Solution

RoutePlanner Constructor